import rx.Observable;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * Created by codeczx on 2017/2/17.
 */
public class TransformDataTest {

    void  testTimeStampInterval(){
        Observable<Long> values = Observable.interval(100,100, TimeUnit.MILLISECONDS);
        values.take(20)
                .timeInterval()
                .subscribe(v->System.out.println(v.getIntervalInMilliseconds()));
        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void testMap(){
        Observable<String> values = Observable.just("1","2","3");
        values.map(Integer::parseInt)
                .subscribe(new PrintSubscriber("map"));
    }

    void testFlatMap(){
        Observable.just(100,150)
                .flatMap(v->Observable.interval(v,TimeUnit.MILLISECONDS).map(i->v))
                .take(30)
                .subscribe(new PrintSubscriber("flatMap"));
        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        TransformDataTest tdt = new TransformDataTest();
//        tdt.testTimeStampInterval();
//        tdt.testMap();
        tdt.testFlatMap();
    }
}
